from typing import List


class Solution:
    def minimumDifference(self, nums: List[int], k: int) -> int:
        nums.sort()
        ans = nums[-1] - nums[0]
        for i in range(len(nums) - k + 1):
            ans = min(ans, nums[i + k - 1] - nums[i])
        return ans


if __name__ == "__main__":
    print(Solution().minimumDifference(nums=[90], k=1))  # 0
    print(Solution().minimumDifference(nums=[9, 4, 1, 7], k=2))  # 2
